package dssd.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

import dssd.constantes.Constantes;
import dssd.modelo.Conductor;
import dssd.modelo.Solicitud;
import dssd.modelo.SolicitudAlta;
import dssd.modelo.SolicitudRenovacion;
import dssd.servicios.ConductorService;
import dssd.servicios.ILicenciasService;

public class VerSolicitudesRenovacion extends VerSolicitud{
	
	private JLabel jLabel5;
	protected JTextField jTextField3;

	public VerSolicitudesRenovacion(){
		super();
		initGUI();
	}
	
	protected JPanel getJPanel2() {
		if(jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.add(getJLabel5());
			jPanel2.add(getJTextField3());
			jPanel2.add(getJButton3());
		}
		return jPanel2;
	}
	


	protected  JButton getJButton3(){
		if(jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setText("Guardar");
			jButton3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					actualizarSolicitud(jTextField3.getText());
					ILicenciasService service = ServiceLocator.getLicenciasService();
					service.actualizarSolicitud(AplicacionEscritorio.getInstance().getUsuario(),solicitud);
					
				}
			});
		}
		return jButton3;
	}
	
	@Override
	protected void preCargarFormulario(Solicitud sol) {
		habilitarInputs();
		SolicitudRenovacion solicitud = (SolicitudRenovacion) sol;
		if ((solicitud.getExamenManejo() != null) && (solicitud.getExamenManejo().getFecha() != null)){
			String str = formatDDMMYYYY(solicitud.getEvaluacionVial().getFecha());
			jTextField3.setText(str);
		}else{
			jTextField3.setText("");
		}
	}	

	private void actualizarSolicitud(String fechaExamenes) {
		if ((fechaExamenes != null) && (!fechaExamenes.equalsIgnoreCase(""))){
			solicitud.getEvaluacionVial().setFecha((new Date(Date.parse(fechaExamenes))));
			solicitud.getExamenManejo().setFecha(new Date(Date.parse(fechaExamenes)));
		}
	}
	/**
	* This method should return an instance of this class which does 
	* NOT initialize it's GUI elements. This method is ONLY required by
	* Jigloo if the superclass of this class is abstract or non-public. It 
	* is not needed in any other situation.
	 */
	public static Object getGUIBuilderInstance() {
		return new VerSolicitudesRenovacion(Boolean.FALSE);
	}
	
	/**
	 * This constructor is used by the getGUIBuilderInstance method to
	 * provide an instance of this class which has not had it's GUI elements
	 * initialized (ie, initGUI is not called in this constructor).
	 */
	public VerSolicitudesRenovacion(Boolean initGUI) {
		super();
	}

	@Override
	protected boolean validaSolicitudTipo(Solicitud solicitud) {
		return solicitud.getTipo().equalsIgnoreCase(Constantes.RENOVACION);
	}

	@Override
	protected void habilitarInputs(boolean bool) {
		getJTextField3().enable(bool);
		getJButton3().enable(bool);
	}
	protected String[] getCabeceraTabla() {
		String[] result =  {"DNI", "Apellido", "Nombre", "Fecha solicitud", "Tipo"};
		return result;
	}
	
	protected JLabel getJLabel5() {
		if(jLabel5 == null) {
			jLabel5 = new JLabel();
			jLabel5.setText("Examen Manejo");
		}
		return jLabel5;
	}
	
	protected JTextField getJTextField3() {
		if(jTextField3 == null) {
			jTextField3 = new JTextField();
			jTextField3.setPreferredSize(new java.awt.Dimension(82, 22));
		}
		return jTextField3;
	}
}